<?php

// TITLE: driversLicense
// FILE: driversLicense.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:53:54 PM
?>

		public function createDriverLicense($id, $number, $stateId, $filePath) {
			global $con;
			$sql = 'INSERT INTO driver_license (id, number, state_id, file_path) VALUES (' . $id . ', ' . $number . ', ' . $stateId . ', ' . $filePath . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readDriverLicense($id) {
			global $con;
			$sql = 'SELECT * FROM driver_license WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$driverLicense = new DriverLicense();
				$driverLicense->setId($result[0]);
				$driverLicense->setNumber($result[1]);
				$driverLicense->setStateId($this->readState($result[2]));
				$driverLicense->setFilePath($result[3]);
			} else {
				$driverLicense = false;
			}
			return $driverLicense;
		}// end function

		public function updateDriverLicense($id, $number, $stateId, $filePath) {
			global $con;
			$sql = 'UPDATE driver_license SET number = ' . $number . ', state_id = ' . $stateId . ', file_path = ' . $filePath . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteDriverLicense($id) {
			global $con;
			$sql = 'DELETE FROM driver_license WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listDriverLicense() {
			global $con;
			$sql = 'SELECT * FROM driver_license';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$driverLicenses = array();
				while ($result = mysqli_fetch_array($results)) {
					$driverLicense = new DriverLicense();
					$driverLicense->setId($result[0]);
					$driverLicense->setNumber($result[1]);
					$driverLicense->setStateId($this->readState($result[2]));
					$driverLicense->setFilePath($result[3]);
					$driverLicenses[] = $driverLicense;
				}// end while
			} else {
				$driverLicenses = false;
			}
			return $driverLicenses;
		}// end function

